from django.contrib.auth.models import AbstractUser
from django.db import models

# Create your models here.
from utils.models import BaseModel


class User(AbstractUser):
    USERNAME_FIELD = 'mobile'
    USER_GENDER_CHOICES = (
        (1, "男"),
        (2, "女"),
    )

    LIFE_STATUS_CHOICES = (
        (1, '单身'),
        (2, '热恋中'),
        (3, '已婚'),
        (4, '为人父母'),
    )
    username = models.CharField(max_length=30, unique=False, verbose_name='昵称')
    mobile = models.CharField(null=True, max_length=11, unique=True, verbose_name='手机号')
    gender = models.SmallIntegerField(choices=USER_GENDER_CHOICES, null=True, verbose_name='性别')
    birthday = models.DateField(null=True, verbose_name='生日')
    life_status = models.SmallIntegerField(choices=LIFE_STATUS_CHOICES, null=True, verbose_name='生活状态')

    job = models.CharField(null=True, max_length=30, verbose_name='工作')
    occupation = models.CharField(null=True, max_length=30, verbose_name='职业')

    signature = models.CharField(null=True, max_length=20, verbose_name='个性签名')

    class Meta:
        db_table = 'tb_user'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class UserHeadImage(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, unique=True, related_name='user_img', verbose_name='头像关联的用户')
    head_image = models.ImageField(max_length=200, default='group1/M00/00/03/wKhVg2DoawiAZrkgAAAk3Qbfmts6653819', null=True, blank=True,
                                   verbose_name='默认图片')

    class Meta:
        db_table = 'tb_user_image'
        verbose_name = '用户头像'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s %s' % (self.user.username, self.id)
